package com.yunxi.controller.dealer;

import com.alibaba.dubbo.config.annotation.Reference;
import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.CurrentUser;
import com.yunxi.core.web.LoginInfo;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.dealer.pojo.PartnerAccountVO;
import com.yunxi.dealer.service.PartnerAccountDubboService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 渠道商帐户 前端控制器
 * </p>
 *
 * @author
 * @since 2019-05-16
 */
@RestController
@RequestMapping("/admin/partner/partnerAccount")
@Api(tags = "partner:partneraccount", description = "渠道商帐户接口")
public class PartnerAccountController {
   private static final Logger logger = LoggerFactory.getLogger(PartnerAccountController.class);

   //   @Reference(version = "${demo.service.version}",
//           application = "${dubbo.application.id}",
//           url = "${dubbo.application.url}",
//           check = false,
//           timeout = 10000)
   @Autowired
   PartnerAccountDubboService partnerAccountDubboService;

   @GetMapping("/page")
   @ApiOperation(value = "查询分页")
   public ApiResult page(PartnerAccountVO partnerAccountVO, Integer pageNum, Integer pageSize, @CurrentUser LoginInfo loginInfo) throws Exception {
      return ResponseUtil.ok(partnerAccountDubboService.findPageByVO(partnerAccountVO, pageNum, pageSize,loginInfo));
   }

   @GetMapping("/load")
   @ApiOperation(value = "读取单个")
   public ApiResult load(PartnerAccountVO partnerAccountVO, @CurrentUser LoginInfo loginInfo) throws Exception {
      return ResponseUtil.ok(partnerAccountDubboService.getById(partnerAccountVO.getAccountId()));
   }

   @PostMapping("/save")
   @ApiOperation(value = "保存信息")
   public ApiResult save(@RequestBody PartnerAccountVO partnerAccountVO, @CurrentUser LoginInfo loginInfo) throws Exception {
      partnerAccountDubboService.saveOrUpdate(partnerAccountVO,loginInfo);
      return ResponseUtil.ok("success");
   }

   @PostMapping("/del")
   @ApiOperation(value = "删除")
   public ApiResult del(@RequestBody PartnerAccountVO partnerAccountVO) throws Exception {
      partnerAccountDubboService.removeById(partnerAccountVO.getAccountId());
      return ResponseUtil.ok("success");
   }

   @GetMapping("/list")
   @ApiOperation(value = "查询列表")
   public ApiResult list(PartnerAccountVO v) throws Exception {
      return ResponseUtil.ok(partnerAccountDubboService.listByVo(v));
   }

   @GetMapping("/loadDetail")
   @ApiOperation(value = "读取账户交易记录")
   @ApiImplicitParams({
           @ApiImplicitParam(paramType="query", name = "datam", value = "记帐起始日期", required = true, dataType = "String"),
           @ApiImplicitParam(paramType="query", name = "datbi", value = "记帐结束日期", required = true, dataType = "String")
   })
   public ApiResult loadDetail(@RequestParam String partnerCode ,@RequestParam String datam ,@RequestParam String datbi) {
      return partnerAccountDubboService.load(partnerCode,datam,datbi);
   }

   @GetMapping("/listByGroup")
   @ApiOperation(value = "读取账户详情")
   public ApiResult listByGroup(PartnerAccountVO partnerAccountVO, @CurrentUser LoginInfo loginInfo) {
      return ResponseUtil.ok(partnerAccountDubboService.listByGroup(partnerAccountVO,loginInfo));
   }

   @GetMapping("/pageByGroup")
   @ApiOperation(value = "读取账户详情")
   public ApiResult listByGroup(PartnerAccountVO partnerAccountVO, Integer pageNum, Integer pageSize,@CurrentUser LoginInfo loginInfo) throws Exception {
      partnerAccountVO.setTenantId("pms");
      return partnerAccountDubboService.pageByGroup(partnerAccountVO,pageNum,pageSize,loginInfo);
   }

/*@PostMapping("/export")
@ApiOperation(value = "导出excel")
public Object export(@RequestParam Map<String,Object> params) throws Exception {
return ResponseUtil.ok(partnerAccountService.findMapByList(params));
}*/
}
